package net.trackhack.powerboard.server;


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import net.trackhack.powerboard.client.PowerBoardEntry;
import net.trackhack.powerboard.client.PowerBoardService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class PowerBoardServiceImpl extends RemoteServiceServlet implements
		PowerBoardService {
	
	ArrayList<PowerBoardEntry> entries = new ArrayList<PowerBoardEntry>();

	public PowerBoardEntry[] getPowerBoard(String trackName) {
		
		//PersistenceManager pm = PMF.get().getPersistenceManager();
		
		
		
		// just some test data for now
		// TODO update to retrive from database


		return entries.toArray(new PowerBoardEntry[entries.size()]);
		
		/*
		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		return "Hello, " + input + "!<br><br>I am running " + serverInfo
				+ ".<br><br>It looks like you are using:<br>" + userAgent;
		*/
	}
	
	public Boolean submitEntry(PowerBoardEntry entry)
	{
		return entries.add(entry);
	}
	
	// parse the lap time given in the following format:
	// [HH:]MM:SS:ssss

}
